<?php
namespace app\index\controller;
use think\Controller;


/*
*  商品 
 */
class Goods extends Controller
{
  
	 public function index()
    {
    	$mall = db('goods')->select();
//        	dump($mall);die;
        $this->assign('title','积分换取区 - 《英雄联盟》官方论坛 - Powered by Discuz!');
		$this->assign('mall', $mall);
		return $this->fetch();
    }
    public function exchange()
    {
    	$user = db('information')->where('userid',$_POST['id'])->find();
        $goods = db('goods')->where('id',$_POST['goodsid'])->find();
        if ($user['jifen'] >= $goods['price']) {
    	    db('goods')->where('id',$_POST['goodsid'])->update(['number'=>($goods['number']-1)]);
    		db('information')->where('userid',$_POST['id'])->update(['jifen'=>($user['jifen'] - $goods['price'])]);
    		db('gral_info')->insert(['uid'=>$_POST['id'],'gid'=>$_POST['goodsid'],'integral'=>$goods['price']]);
    		return 0;
    	}else{
    		return 1;
    	}
    	// return $_POST['id'].$_POST['goodsid'];
    }

}
